<template>
  <div class="pop-dialog-container">
    <div class="pop-dialog-main">
    <el-form label-position="right" :model="parkingChargeForm" :label-width="formLabelWidth" disabled="disabled">
      <el-row>
        <el-col :span="11">
          <el-form-item label="车位号">
            <el-input v-model="parkingChargeForm.parkingAreaNumber"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="单元房号">
            <el-input v-model="parkingChargeForm.residentRoomNumber"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="车牌">
            <el-input v-model="parkingChargeForm.licensePlate"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="使用开始时间">
            <el-input v-model="parkingChargeForm.billingStartDate"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="使用结束时间">
            <el-input v-model="parkingChargeForm.billingEndDate"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="金额">
            <el-input v-model="parkingChargeForm.amount"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="备注">
            <el-input v-model="parkingChargeForm.remark"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="创建时间">
            <el-input v-model="parkingChargeForm.createTime"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    </div>
    <div class="pop-dialog-footer">
      <el-row>
        <el-col :span="12" :offset="6">
          <div class="form-button-container">
            <el-button @click="onBack" type="primary">关闭</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup lang="ts">
import {defineEmits, defineProps, onMounted, reactive, ref, inject, toRefs} from 'vue';
import parkingChargeApi from '@/api/parkingChargeApi'
import type {ParkingCharge} from "@/types/resp/parkingCharge";
import type {Id} from "@/types/id"

const parkingChargeForm = reactive<Partial<ParkingCharge>>({});
const props = defineProps<Id>()
const emit = defineEmits<{
  (e: 'closeParkingChargeViewEvent'): void;
}>()
const formLabelWidth = ref<string>('')

onMounted(() => {
  initParkingChargeById(props.id)
  const globalState = inject('globalState', {} as { formLabelWidth?: string })
  if (!globalState) {
    throw new Error('globalState is not provided');
  }
  const globalStateRefs = toRefs(globalState)
  if (globalStateRefs.formLabelWidth) {
    formLabelWidth.value = globalStateRefs.formLabelWidth.value || ''
  }
})

const initParkingChargeById = async (id: number) => {
  const resp = await parkingChargeApi.findById(id)
  if (resp && resp.code === 1 && resp.data) {
    Object.assign(parkingChargeForm, resp.data)
  }
}
const onBack = () => {
  emit('closeParkingChargeViewEvent')
}
</script>

<style lang="scss">
</style>